package huoye.shops.huoye.mine.presenter;


import android.app.Activity;
import android.os.CountDownTimer;
import android.util.Log;

import com.codeideology.android.rpc.BaseJsonRequestCallback;
import com.codeideology.android.utils.StringUtils;

import huoye.shops.MainActivity;
import huoye.shops.R;
import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.base.UserManager;
import huoye.shops.base.ZybCallBack;
import huoye.shops.huoye.mine.activity.WithdrawEndActivity;
import huoye.shops.huoye.mine.model.ShopDetials;
import huoye.shops.huoye.mine.model.WithdrawHome;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IWithdrawView;
import huoye.shops.huoye.user.model.UpdateInfo;
import huoye.shops.huoye.user.model.User;
import huoye.shops.huoye.user.network.UserService;
import huoye.shops.huoye.user.view.ILoginView;
import okhttp3.Call;


/**
 * Created by uesr on 2017/7/19.
 */

public class WithdrawPresenter extends BasePresenter<IWithdrawView> {


    private MineService mService;



    //获取商家提现页面数据
    public void getDepositIndex(){
        //view.showProcessingIndicator();
            mService.getDepositIndex(new MineBaseJsonRequestCallback<WithdrawHome>(WithdrawHome.class) {

                @Override
                public void onSuccess(WithdrawHome withdrawHome) {
                    super.onSuccess(withdrawHome);
                    view.setWithdrawData(withdrawHome);
                }

                //网络请求失败
                @Override
                public void onFailure(String msg, String code, Throwable e) {
                    super.onFailure(msg, code, e);
                    view.makeToast(msg);
                    //   Log.e("testaaa",msg);
                }

                //加载结束
                @Override
                public void onNetworkFail() {
                    super.onNetworkFail();
                    view.onNetworkFail();
                }

                //加载中
                @Override
                public void onFinish() {
                    super.onFinish();
                    view.hideProcessingIndicator();
                }
            });
    }





    //商户提现申请
    public void Withdraw(String momey,String account){
        if (momey.equals("")){
            view.makeToast("请输入提现金额");
            return;
        }else if(account.equals("")){
            view.makeToast("请输入卡号");
            return;
        }else {
            view.showProcessingIndicator();
            mService.Withdraw(momey,account,new MineBaseJsonRequestCallback<User>(User.class) {

                @Override
                public void onSuccess(User user) {
                    super.onSuccess(user);
                    view.makeToast("提现申请成功！");
                    view.finish();
                    view.startActivity(WithdrawEndActivity.class);
                }

                //网络请求失败
                @Override
                public void onFailure(String msg, String code, Throwable e) {
                    super.onFailure(msg, code, e);
                    view.makeToast(msg);
                    //   Log.e("testaaa",msg);
                }

                //加载结束
                @Override
                public void onNetworkFail() {
                    super.onNetworkFail();
                    view.onNetworkFail();
                }

                //加载中
                @Override
                public void onFinish() {
                    super.onFinish();
                    view.hideProcessingIndicator();
                }
            });
        }
    }


    @Override
    public void onStart() {
        mService = new MineService();
    }
}
